<%@ page contentType="text/html; charset=utf-8" import="com.running.util.StringUtils,com.running.crm.model.Staff"%><%
String phoneNo = StringUtils.varFormat(request.getParameter("phoneNo"));
Staff staff = (Staff)request.getAttribute("loginStaff");
%>
<html>
<head>
<xml id="xmlSmsConfig" src="smsConfig.do?method=listXML"></xml>
<script language="javascript">
    var smsFlag = true;
	window.onload = function Init(){
	  // alert(document.getElementById("mtDstNumId"));
		PageInit();
	}
	function PageInit() {
		loadXMLData2Select(document.forms[0].smsConfig,xmlSmsConfig.xml,"smsSubject","smsContent","","|----选择短信模板----");
		buildSms();
	}
	function buildSms() {
		document.forms[0].mtContent.value = document.forms[0].smsConfig.value;
		calculateSms(document.forms[0].mtContent);
	}
	
	function Choice()
	{
		var returnValue = showModalDialog("customer.do?method=choice&textColumn=phoneInfo&valueColumn=phoneNo&temp="+Math.random(),document.oForm,"dialogWidth:53em; dialogHeight:42em; status:0");
		if (returnValue != null) {
		  
		  var s = returnValue[0].split(/\D/g).length;//以1,1形式为两个字符
		if(s>10000){
		      alert("您导入的手机号码超过10000条，请按批次导入!");
		 }else{
			 if (oForm.mtDstNum.value=="") {
				 oForm.mtDstNum.value = returnValue[0];
			  } else {
				 oForm.mtDstNum.value += ","+returnValue[0];
			 }
			   calculatePhone(oForm.mtDstNum);
		 }
	  }
	}
	function beforeSubmit(oForm) {
		var phoneNo = oForm.mtDstNum.value.replace(/\D/g,"\r\n");
		//去除可能重复的手机号码
		//oForm.mtDstNum.value = phoneNo.split(',').sort().join(',').replace(/(\d{11},)\1+/g, '$1');
		oForm.mtDstNum.value = phoneNo.split(/\D/g).sort().join('\r\n').replace(/(\d{11}\r\n)\1+/g, '$1');
		if (ValidateForm(oForm)) {
			return true;
		} else {
			return false;
		}
	}
	function WapPush(obj) {
		if (obj.checked)
			oForm.mtUrlLink.disabled=false;
		else
			oForm.mtUrlLink.disabled=true;
	}
	function calculateSms(obj) {
		var mt_content = obj.value + oForm.smsSign.value;
		var s = "共"+mt_content.length+"个字,共计为";
		if (mt_content.length <= 70) {
			s += "1"+"条短信";
		} else {
			if (mt_content.length%70 > 0) {
				s += (parseInt(mt_content.length/70) + 1)+"条短信";
			} else {
				s += (parseInt(mt_content.length/70))+"条短信";
			}
		}
		document.getElementById("smsTip").innerHTML = s;
	}

	function calculatePhone(obj) {
	    
		var s = obj.value.split(/\D/g).length;//以1,1形式为两个字符
		if(s>10000){
		   alert("您导入的手机号码超过10000条，请按批次导入!");
		}else{
		   document.getElementById("phoneTip").innerHTML = "共有"+s+"个电话号码";
		   document.oForm.mtDstNum.value = obj.value.split(/\D/g).sort().join('\r\n').replace(/(\d{11}\r\n)\1+/g, '$1');
		}
		   
	}
	function clearPhones(){
	    document.oForm.mtDstNum.value="";
	    document.getElementById("phoneTip").innerHTML = "共有0个电话号码";
	}
</script>
</head>
<body>
<form name="oForm" onsubmit="return beforeSubmit(this)" method="POST" action="sms.do?method=save">
<input type="hidden" name="smsSign" value="<%=StringUtils.varFormat(staff.getCompany().getSmsSign()) %>"/>

<table id="FormTable">
<caption>向您的客户发送短信</caption>
<tr><td colspan="2"><font class="FieldItem">手机号码<font class="NotNull">(*必填项)<span id="phoneTip">共有0个电话号码</span></font></font>&nbsp;&nbsp;<input type="button"  class="DefaultButton" value="导入客户号码" onclick="Choice()" />&nbsp;<input type="button"  class="DefaultButton" value="清除客户号码" onclick="clearPhones()" /><br/><textarea name="mtDstNum" id="mtDstNumId" _cnName="接收短信手机号" _dataType="String" _dataLength="129998" _dataEmpty="false"  style="height:80px" readonly><%=phoneNo %></textarea></td></tr>
<tr><td colspan="2"><font class="FieldItem">短信内容<font class="NotNull">(*必填项)<span id="smsTip"></span></font></font><br/><select name="smsConfig" onchange="buildSms()"></select><br/><textarea name="mtContent" _dataType="string" _cnName="短信内容" _cDataLength="255" _dataEmpty="false" onkeyup="calculateSms(this)" onblur="calculateSms(this)" style="height:80px"></textarea><br/><B>短信签名:<%=StringUtils.varFormat(staff.getCompany().getSmsSign()) %></B></td></tr>
<tr><td colspan="2"><font class="FieldItem">WAP PUSH选项</font><br/><table><tr><td width="30%"><input type="checkbox" style="vertical-align:text-bottom; margin-bottom:2px; *margin-bottom:-2px;width:18px" onclick="WapPush(this)">作为WAP PUSH发送</td><td width="70%">http://<input type="text" name="mtUrlLink" value="<%=request.getLocalAddr()+"/wap/"+staff.getCompany().getCorpAccount() %>" style="vertical-align:text-bottom; margin-bottom:2px; *margin-bottom:-2px;" disabled="true"/></td></tr></table></td></tr>
<tr><td colspan="2"><font class="FieldItem">发送时间<font class="NotNull">[使用该项可以支持定时发送功能]</font></font><br/><input name="mtAtTime" _dataType="string" _cnName="发送时间" _dataLength="255" class="defaultCalendar"></td></tr>
<tr><td colspan="2"><HR/></td></tr>
<tr><td><input type="submit" name="btnSubmit" value="发送短信" class="DefaultButton"/>&nbsp;<input type="button" name="btnCancel" value=" 取 消 " class="DefaultBtnCancel"/></td></tr>
</table>
</form>
</body>
</html>